import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Window 2.12

ApplicationWindow {
    id: applicationWindow
    visible: true
    width: 800
    height: 480
    title: qsTr("好粮数据采集V1.0.0")

    property QtObject cdata: collect

    Window{
        id:dialog
        width: 300
        height: 200
        title: "提示"
      Rectangle{
        anchors.fill: parent
        Text {
            id: dialogtext
            anchors.fill: parent
            anchors.bottom: dialogbut.top
            text: qsTr("text")

            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
        }
        Button{
            id:dialogbut
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 5
            anchors.right: parent.right
            anchors.rightMargin: 5
            text: "确定"
            onClicked: dialog.close()
        }
       }
    }
    Connections{
        target: cdata
        onChangMessage:{
            console.log("m:"+msg)
            dialogtext.text=msg;
            dialog.show();
        }
        onShowDatas:{
            textArea.text =msg;
        }
    }
    ScrollView {
        id: scrollView
        anchors.topMargin: 9
        anchors.rightMargin: 10
        anchors.left: column.right
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.top: parent.top
        anchors.bottomMargin: 120
        anchors.leftMargin: 10

        ListView {
            id:listv
            x: 200
            y: 0
            width: 600
            anchors.left: parent.left
            anchors.leftMargin: 0
            anchors.right: parent.right
            anchors.rightMargin: 0
            model:cdata.getIitems()
            delegate: Row {
                width: parent.width
                height: 40
                Text {
                    text: qsTr(" ID:"+model.modelData.id)
                    anchors.verticalCenter: parent.verticalCenter
                }
                Text {
                    text: qsTr(" 样品："+model.modelData.sample)
                    anchors.verticalCenter: parent.verticalCenter
                }
                Text {
                    text: qsTr(" 编号:"+model.modelData.number)
                    anchors.verticalCenter: parent.verticalCenter
                }
                Text {
                    text: qsTr(" "+model.modelData.datetime)
                    anchors.verticalCenter: parent.verticalCenter
                }
                Text {
                    text: qsTr(" 第"+model.modelData.index +"次测验")
                    anchors.verticalCenter: parent.verticalCenter
                }
                Text {
                    text: qsTr(" 值:"+model.modelData.value.toFixed(model.modelData.precision))
                    anchors.verticalCenter: parent.verticalCenter
                }

                Text {
                    text: qsTr(" 连续差值："+model.modelData.tolerance.toFixed(model.modelData.precision) )
                    color: model.modelData.istolerance?"green":"red"
                    anchors.verticalCenter: parent.verticalCenter
                }
            }
        }
    }

    Column {
        id: column
        width: 200
        spacing: 2
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 10
        anchors.top: parent.top
        anchors.topMargin: 10

        Text {
            id: element
            text: qsTr("ID")
            font.pixelSize: 12
        }

        TextField {
            id: textField
            height: 30
            text: cdata.id
            placeholderText: qsTr("每次测验的唯一编号")
            enabled:false
        }

        Text {
            id: element1
            text: qsTr("项目")
            font.pixelSize: 12
        }

        TextField {
            id: textField1
            height: 30
            text: cdata.item
            placeholderText: qsTr("测验数据的项目")
            enabled: false
        }

        Text {
            id: element2
            text: qsTr("产品")
            font.pixelSize: 12
        }

        TextField {
            id: textField2
            height: 30
            text: cdata.product
            placeholderText: qsTr("样本产品名称")

        }

        Text {
            id: element3
            text: qsTr("样本编号")
            font.pixelSize: 12
        }


        TextField {
            id: textField3
            height: 30
            text: cdata.samplenuber
            placeholderText: qsTr("测验样本编号")
            validator: IntValidator{ bottom:0}
            onTextChanged:cdata.samplenuber=Number(text)
        }

        Text {
            id: element4
            text: qsTr("容差")
            font.pixelSize: 12
        }

        TextField {
            id: textField4
            height: 30
            text: cdata.tolerance
            placeholderText: qsTr("连续二次测验的最大差")
            validator: DoubleValidator{ notation : DoubleValidator.StandardNotation}
            onTextChanged:cdata.tolerance=Number(text)
        }

        Text {
            id: element5
            text: qsTr("日期")
            font.pixelSize: 12
        }

        TextField {
            id: textField5
            height: 30
            text: cdata.datetime
            placeholderText: qsTr("当天日期")
            enabled: false
        }

        Text {
            id: element6
            text: qsTr("数值")
            font.pixelSize: 12
        }

        TextField {
            id: textField6
            placeholderText: qsTr("测验的结果值")
            text:cdata.value
            validator: DoubleValidator{bottom: 0; notation : DoubleValidator.StandardNotation}
            focus: true
            onTextChanged:cdata.value=Number(text)

        }

        Button {
            id: button
            text: qsTr("保存")
            onPressed: {
                cdata.save()
                listv.model=cdata.getIitems()
            }
        }

        Button {
            id: button1
            text: qsTr("下一个")
            onPressed: cdata.next()
        }

    }

    Rectangle {
        id: rectangle
        color: "#f2efef"
        radius: 10
        border.color: "#d06459"
        anchors.left: column.right
        anchors.leftMargin: 10
        anchors.top: scrollView.bottom
        anchors.topMargin: 10
        anchors.right: parent.right
        anchors.rightMargin: 10
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 10

        TextArea {
            id: textArea
            text: "样本： 编号：0 测量：0次  均值：0"
            anchors.rightMargin: 10
            anchors.leftMargin: 10
            anchors.bottomMargin: 10
            anchors.topMargin: 10
            anchors.fill: parent
            placeholderText: qsTr("统计结果")
            enabled: false
        }
    }



}

/*##^##
Designer {
    D{i:2;anchors_width:800}D{i:1;anchors_width:800}D{i:4;anchors_height:400;anchors_x:0;anchors_y:11}
D{i:21;anchors_height:200;anchors_width:200}
}
##^##*/
